//@author A0101056Y
//Singleton protocal
//EventStorage class is a singleton, follow standard singelton usage
//so that there will be only one instance of this object during runtime
//This class stores all the Event objects. All logic-related classes
//can access the storage by: 
//	EventStorage* ptrName = &EventStorage::get(); 
//	EventVector* EventList; 
//	EventList = ptrName -> getEventVecotrPtr();

//This class also saves all the events into file and load all the 
//events from file. E.g. 
//to save file: 
//	EventStorage* ptrName = &EventStorage::get(); 
//	ptrName -> saveFile();

//to load file: 
//	EventStorage* ptrName = &EventStorage::get(); 
//	ptrName -> loadFile();


//@author A0083782W
#pragma once

#include "Event.h"
#include <fstream>
#include <iostream>

using namespace GetCurrentTimeFunctions;
using std::vector;
using std::string;
using std::fstream;
using std::endl;
using std::getline;
using std::ios;
using StringManipulator::isNumString;

typedef vector<Event> EventVector;

class EventStorage {
private:
	Time _startDay;
	static string const fileName; 
	EventVector _eventData;
	EventStorage();
	EventStorage (const EventStorage&);
	EventStorage& operator = ( const EventStorage&);
	static bool hasRun;
	void writeTimeToFile (const Time& timer, fstream& fp) const;
	void writeEventToFile (Event& theEvent, fstream& fp) const;
	Time readTimeFromFile ( fstream& fp);
	Event readEventFromFile (fstream& fp);

public:
	~EventStorage();
	//only instance
	static EventStorage& get();

	EventVector* getEventVectorPtr();
	
	//To check if a day has passed
	Time getStartDay();
	void readFile();
	void saveFile();
};

typedef EventStorage * const EventStoragePtr;